package org.jeecg.modules.demo.hd.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.demo.hd.entity.AppMyProjectDetail;
import org.jeecg.modules.demo.hd.service.IAppMyProjectDetailService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.demo.hd.vo.myProject.MyProjectDetailDayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

/**
 * @Description: 用户项目每日完成情况
 * @Author: jeecg-boot
 * @Date: 2025-04-18
 * @Version: V1.0
 */
@Api(tags = "用户项目每日完成情况")
@RestController
@RequestMapping("/hd/appMyProjectDetail")
@Slf4j
public class AppMyProjectDetailController extends JeecgController<AppMyProjectDetail, IAppMyProjectDetailService> {
    @Autowired
    private IAppMyProjectDetailService appMyProjectDetailService;

    /**
     * 分页列表查询
     *
     * @param appMyProjectDetail
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation(value = "用户项目完成情况", notes = "用户项目完成情况")
    @GetMapping(value = "/list")
    public Result<IPage<AppMyProjectDetail>> queryPageList(AppMyProjectDetail appMyProjectDetail,
                                                           @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                           HttpServletRequest req) {
        QueryWrapper<AppMyProjectDetail> queryWrapper = QueryGenerator.initQueryWrapper(appMyProjectDetail, req.getParameterMap());
        Page<AppMyProjectDetail> page = new Page<AppMyProjectDetail>(pageNo, pageSize);
        IPage<AppMyProjectDetail> pageList = appMyProjectDetailService.page(page, queryWrapper);
        return Result.OK(pageList);
    }


    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "app_my_project_detail-通过id查询", notes = "app_my_project_detail-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<AppMyProjectDetail> queryById(@RequestParam(name = "id", required = true) String id) {
        AppMyProjectDetail appMyProjectDetail = appMyProjectDetailService.getById(id);
        if (appMyProjectDetail == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(appMyProjectDetail);
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "查询项目当月完成情况", notes = "查询项目当月完成情况")
    @GetMapping(value = "/queryByProjectId")
    public Result<List<MyProjectDetailDayVo>> queryByProjectId(@RequestParam(name = "id", required = true) String id) {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        List<MyProjectDetailDayVo> dataList = appMyProjectDetailService.queryByProjectId(sysUser.getId(), id);
        return Result.OK(dataList);
    }


}
